home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / libgimp / gimpgradients_pdb.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-26  |  6.3 KB  |  215 lines

  1. /* LIBGIMP - The GIMP Library
  2.  * Copyright (C) 1995-2000 Peter Mattis and Spencer Kimball
  3.  *
  4.  * gimpgradients_pdb.c
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Lesser General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Lesser General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Lesser General Public
  17.  * License along with this library; if not, write to the
  18.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.  * Boston, MA 02111-1307, USA.
  20.  */
  21.  
  22. /* NOTE: This file is autogenerated by pdbgen.pl */
  23.  
  24. #include <string.h>
  25.  
  26. #include "gimp.h"
  27.  
  28. /**
  29.  * gimp_gradients_get_list:
  30.  * @num_gradients: The number of loaded gradients.
  31.  *
  32.  * Retrieve the list of loaded gradients.
  33.  *
  34.  * This procedure returns a list of the gradients that are currently
  35.  * loaded in the gradient editor. You can later use the
  36.  * gimp_gradients_set_active function to set the active gradient.
  37.  *
  38.  * Returns: The list of gradient names.
  39.  */
  40. gchar **
  41. gimp_gradients_get_list (gint *num_gradients)
  42. {
  43.   GimpParam *return_vals;
  44.   gint nreturn_vals;
  45.   gchar **gradient_names = NULL;
  46.   gint i;
  47.  
  48.   return_vals = gimp_run_procedure ("gimp_gradients_get_list",
  49.                     &nreturn_vals,
  50.                     GIMP_PDB_END);
  51.  
  52.   *num_gradients = 0;
  53.  
  54.   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
  55.     {
  56.       *num_gradients = return_vals[1].data.d_int32;
  57.       gradient_names = g_new (gchar *, *num_gradients);
  58.       for (i = 0; i < *num_gradients; i++)
  59.     gradient_names[i] = g_strdup (return_vals[2].data.d_stringarray[i]);
  60.     }
  61.  
  62.   gimp_destroy_params (return_vals, nreturn_vals);
  63.  
  64.   return gradient_names;
  65. }
  66.  
  67. /**
  68.  * gimp_gradients_get_active:
  69.  *
  70.  * Retrieve the name of the active gradient.
  71.  *
  72.  * This procedure returns the name of the active gradient in the
  73.  * gradient editor.
  74.  *
  75.  * Returns: The name of the active gradient.
  76.  */
  77. gchar *
  78. gimp_gradients_get_active (void)
  79. {
  80.   GimpParam *return_vals;
  81.   gint nreturn_vals;
  82.   gchar *name = NULL;
  83.  
  84.   return_vals = gimp_run_procedure ("gimp_gradients_get_active",
  85.                     &nreturn_vals,
  86.                     GIMP_PDB_END);
  87.  
  88.   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
  89.     name = g_strdup (return_vals[1].data.d_string);
  90.  
  91.   gimp_destroy_params (return_vals, nreturn_vals);
  92.  
  93.   return name;
  94. }
  95.  
  96. /**
  97.  * gimp_gradients_set_active:
  98.  * @name: The name of the gradient to set.
  99.  *
  100.  * Sets the specified gradient as the active gradient.
  101.  *
  102.  * This procedure lets you set the specified gradient as the active or
  103.  * \"current\" one. The name is simply a string which corresponds to
  104.  * one of the loaded gradients in the gradient editor. If no matching
  105.  * gradient is found, this procedure will return an error. Otherwise,
  106.  * the specified gradient will become active and will be used for
  107.  * subsequent custom gradient operations.
  108.  *
  109.  * Returns: TRUE on success.
  110.  */
  111. gboolean
  112. gimp_gradients_set_active (gchar *name)
  113. {
  114.   GimpParam *return_vals;
  115.   gint nreturn_vals;
  116.   gboolean success = TRUE;
  117.  
  118.   return_vals = gimp_run_procedure ("gimp_gradients_set_active",
  119.                     &nreturn_vals,
  120.                     GIMP_PDB_STRING, name,
  121.                     GIMP_PDB_END);
  122.  
  123.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  124.  
  125.   gimp_destroy_params (return_vals, nreturn_vals);
  126.  
  127.   return success;
  128. }
  129.  
  130. /**
  131.  * gimp_gradients_sample_uniform:
  132.  * @num_samples: The number of samples to take.
  133.  *
  134.  * Sample the active gradient in uniform parts.
  135.  *
  136.  * This procedure samples the active gradient from the gradient editor
  137.  * in the specified number of uniform parts. It returns a list of
  138.  * floating-point values which correspond to the RGBA values for each
  139.  * sample. The minimum number of samples to take is 2, in which case
  140.  * the returned colors will correspond to the { 0.0, 1.0 } positions in
  141.  * the gradient. For example, if the number of samples is 3, the
  142.  * procedure will return the colors at positions { 0.0, 0.5, 1.0 }.
  143.  *
  144.  * Returns: Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }.
  145.  */
  146. gdouble *
  147. gimp_gradients_sample_uniform (gint num_samples)
  148. {
  149.   GimpParam *return_vals;
  150.   gint nreturn_vals;
  151.   gdouble *color_samples = NULL;
  152.   gint num_color_samples;
  153.  
  154.   return_vals = gimp_run_procedure ("gimp_gradients_sample_uniform",
  155.                     &nreturn_vals,
  156.                     GIMP_PDB_INT32, num_samples,
  157.                     GIMP_PDB_END);
  158.  
  159.   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
  160.     {
  161.       num_color_samples = return_vals[1].data.d_int32;
  162.       color_samples = g_new (gdouble, num_color_samples);
  163.       memcpy (color_samples, return_vals[2].data.d_floatarray,
  164.           num_color_samples * sizeof (gdouble));
  165.     }
  166.  
  167.   gimp_destroy_params (return_vals, nreturn_vals);
  168.  
  169.   return color_samples;
  170. }
  171.  
  172. /**
  173.  * gimp_gradients_sample_custom:
  174.  * @num_samples: The number of samples to take.
  175.  * @positions: The list of positions to sample along the gradient.
  176.  *
  177.  * Sample the active gradient in custom positions.
  178.  *
  179.  * This procedure samples the active gradient from the gradient editor
  180.  * in the specified number of points. The procedure will sample the
  181.  * gradient in the specified positions from the list. The left endpoint
  182.  * of the gradient corresponds to position 0.0, and the right endpoint
  183.  * corresponds to 1.0. The procedure returns a list of floating-point
  184.  * values which correspond to the RGBA values for each sample.
  185.  *
  186.  * Returns: Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }.
  187.  */
  188. gdouble *
  189. gimp_gradients_sample_custom (gint     num_samples,
  190.                   gdouble *positions)
  191. {
  192.   GimpParam *return_vals;
  193.   gint nreturn_vals;
  194.   gdouble *color_samples = NULL;
  195.   gint num_color_samples;
  196.  
  197.   return_vals = gimp_run_procedure ("gimp_gradients_sample_custom",
  198.                     &nreturn_vals,
  199.                     GIMP_PDB_INT32, num_samples,
  200.                     GIMP_PDB_FLOATARRAY, positions,
  201.                     GIMP_PDB_END);
  202.  
  203.   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
  204.     {
  205.       num_color_samples = return_vals[1].data.d_int32;
  206.       color_samples = g_new (gdouble, num_color_samples);
  207.       memcpy (color_samples, return_vals[2].data.d_floatarray,
  208.           num_color_samples * sizeof (gdouble));
  209.     }
  210.  
  211.   gimp_destroy_params (return_vals, nreturn_vals);
  212.  
  213.   return color_samples;
  214. }
  215.